library(Seurat)
library(SeuratDisk)
library(reticulate)
library(scrubletR)
library(ggplot2)
library(patchwork)
library(dplyr)
library(data.table)
library(clustree)
library(reshape2)
library(tidyr)
library(gridExtra)
library(stringr)
library(plyr)
source("C:/Ryan/GitHub/trachtenberg-lab/transcriptomics/tools/seurat_functions.R")
source("C:/Ryan/GitHub/trachtenberg-lab/transcriptomics/tools/seurat_integration_functions.R")
source("C:/Ryan/GitHub/trachtenberg-lab/transcriptomics/xgboost/xgboost_train.R")
source("C:/Ryan/GitHub/trachtenberg-lab/transcriptomics/xgboost/plottingFxns.R")
# obj.opossum.glutamatergic <- readRDS("E:/Transcriptomics_V1/Opossum/seurat/opossum_v1_glutamatergic_processed.rds")
obj.opossum.glutamatergic$subclass <- obj.opossum.glutamatergic$SCT_snn_res.2
obj.opossum.glutamatergic$type <- obj.opossum.glutamatergic$SCT_snn_res.2
obj.mouse.glutamatergic.P38 <- readRDS("E:/Transcriptomics_V1/Mouse/seurat/mouse_v1_P38_glutamatergic_processed.rds")
obj.mouse.glutamatergic.P38$species <- "Mouse"
objs <- list(obj.opossum.glutamatergic, obj.mouse.glutamatergic.P38)
obj.integrated <- IntegrateObjects(objs[[1]], objs[[2]], resolutions = c(1), nfeatures = 6000, subsample = TRUE)
| | 0 % ~calculating
|+++++++++++++++++++++++++ | 50% ~10s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=20s
Finding all pairwise anchors
| | 0 % ~calculating
Running CCA
Merging objects
Finding neighborhoods
Finding anchors
Found 21290 anchors
Filtering anchors
Retained 10950 anchors
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=12m 48s
sct.model: model1
Setting min_variance based on median UMI: 0.04
Calculating residuals of type pearson for 6809 genes
|
| | 0%
|
|======= | 4%
|
|============== | 7%
|
|===================== | 11%
|
|============================ | 15%
|
|=================================== | 19%
|
|========================================== | 22%
|
|================================================ | 26%
|
|======================================================= | 30%
|
|============================================================== | 33%
|
|===================================================================== | 37%
|
|============================================================================ | 41%
|
|=================================================================================== | 44%
|
|========================================================================================== | 48%
|
|================================================================================================= | 52%
|
|======================================================================================================== | 56%
|
|=============================================================================================================== | 59%
|
|====================================================================================================================== | 63%
|
|============================================================================================================================= | 67%
|
|==================================================================================================================================== | 70%
|
|=========================================================================================================================================== | 74%
|
|================================================================================================================================================= | 78%
|
|======================================================================================================================================================== | 81%
|
|=============================================================================================================================================================== | 85%
|
|====================================================================================================================================================================== | 89%
|
|============================================================================================================================================================================= | 93%
|
|==================================================================================================================================================================================== | 96%
|
|===========================================================================================================================================================================================| 100%
sct.model: model1
Setting min_variance based on median UMI: 0.04
Calculating residuals of type pearson for 6809 genes
|
| | 0%
|
|======= | 4%
|
|============== | 7%
|
|===================== | 11%
|
|============================ | 15%
|
|=================================== | 19%
|
|========================================== | 22%
|
|================================================ | 26%
|
|======================================================= | 30%
|
|============================================================== | 33%
|
|===================================================================== | 37%
|
|============================================================================ | 41%
|
|=================================================================================== | 44%
|
|========================================================================================== | 48%
|
|================================================================================================= | 52%
|
|======================================================================================================== | 56%
|
|=============================================================================================================== | 59%
|
|====================================================================================================================== | 63%
|
|============================================================================================================================= | 67%
|
|==================================================================================================================================== | 70%
|
|=========================================================================================================================================== | 74%
|
|================================================================================================================================================= | 78%
|
|======================================================================================================================================================== | 81%
|
|=============================================================================================================================================================== | 85%
|
|====================================================================================================================================================================== | 89%
|
|============================================================================================================================================================================= | 93%
|
|==================================================================================================================================================================================== | 96%
|
|===========================================================================================================================================================================================| 100%
Merging dataset 2 into 1
Extracting anchors for merged samples
Finding integration vectors
Finding integration vector weights
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Integrating data
Warning: sparse->dense coercion: allocating vector of size 1.7 GiBWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(condition$message, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(prefix, message) :
NAs introduced by coercion to integer range
Warning: NAs introduced by coercion to integer rangeWarning in paste(new, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(new, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(new, collapse = "\n") :
NAs introduced by coercion to integer range
Warning in paste(new, collapse = "\n") :
NAs introduced by coercion to integer range
subclasses <- c(c("L2/3", "L4", "L5IT", "L5NP", "L5PT", "L6CT", "L6IT", "L6b"), as.character(1:27))
PlotIntegration(obj.integrated, "species", c("integrated_snn_res.1"), subclasses)








objs.i <- SplitObject(obj.integrated, split.by = "species")
objs.m <- MapObjects(objs.i[[1]], objs.i[[2]], c("subclass", "type"), assay = "integrated")
































DimPlot(obj.mouse.glutamatergic.P38, group.by = "subclass", label = TRUE, raster = FALSE) + NoLegend() + xlim(-18, 18) + ylim(-18, 18) + coord_equal()

vfs <- VariableFeatures(obj.mouse.glutamatergic.P38[["SCT"]])
for (vf in 1:20) {
p <- FeaturePlot(obj.mouse.glutamatergic.P38, features = vfs[vf], max.cutoff = 10, raster = FALSE) + xlim(-18, 18) + ylim(-18, 18) + coord_equal()
print(p)
}
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.Scale for y is already present.
Adding another scale for y, which will replace the existing scale.




















DimPlot(obj.opossum.glutamatergic, group.by = "SCT_snn_res.1", label = TRUE, raster = FALSE) + NoLegend() + xlim(-18, 18) + ylim(-18, 18) + coord_equal()

vfs <- VariableFeatures(obj.opossum.glutamatergic[["SCT"]])
for (vf in 21:40) {
p <- FeaturePlot(obj.opossum.glutamatergic, features = vfs[vf], max.cutoff = 10, raster = FALSE) + xlim(-18, 18) + ylim(-18, 18) + coord_equal()
print(p)
}
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.Scale for y is already present.
Adding another scale for y, which will replace the existing scale.




















Idents(obj.opossum.glutamatergic) <- "SCT_snn_res.1"
obj.opossum.glutamatergic.IT <- subset(obj.opossum.glutamatergic, idents = c(2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 17, 19))
obj.opossum.glutamatergic.IT <- ClusterSCT(obj.opossum.glutamatergic.IT, resolutions = c(1))
PlotClusters(obj.opossum.glutamatergic.IT, group.id = "SCT_snn_res.1")
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.Scale for y is already present.
Adding another scale for y, which will replace the existing scale.Scale for x is already present.
Adding another scale for x, which will replace the existing scale.Scale for y is already present.
Adding another scale for y, which will replace the existing scale.









LS0tDQp0aXRsZTogIlIgTm90ZWJvb2siDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0t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